package com.yztc.youbadbad.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.youbadbad.R;
import com.yztc.youbadbad.bean.homepage.Other2GoodBean;
import com.yztc.youbadbad.helper.BitmapCircleTransformation;
import com.yztc.youbadbad.helper.RecyclerViewAdapterHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Tiffany.V.Chou on 2016/11/17.
 */

public class OtherGoodRecyclerAdapter extends RecyclerViewAdapterHelper<Other2GoodBean.ListBean> {

    public OtherGoodRecyclerAdapter(Context context, List<Other2GoodBean.ListBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_other_good_item, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;
        Other2GoodBean.ListBean goodBean = mList.get(position);
        if (goodBean.getUser_info().getNick_name()!=null){
            vh.nickName.setText(goodBean.getUser_info().getNick_name());
        }else {
            vh.nickName.setText("匿名用户");
        }

        vh.zanNum.setText(goodBean.getZan_num()+"");


        if (goodBean.getContent().contains("%")){
            vh.content.setText("收到了,宝贝很好，大家一起买~~");
        }else {
            vh.content.setText(goodBean.getContent());
        }

        if (goodBean.getUser_info().getAvatar()!= null){
             Glide.with(mContext).
                load(goodBean.
                        getUser_info().
                        getAvatar()).
                transform(new BitmapCircleTransformation(mContext)).
                into(vh.avatar);
        }
        Glide.with(mContext).load(goodBean.getShow_image()).into(vh.showImage);
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.show_image)
        ImageView showImage;
        @BindView(R.id.avatar)
        ImageView avatar;
        @BindView(R.id.nick_name)
        TextView nickName;
        @BindView(R.id.content)
        TextView content;
        @BindView(R.id.zan_num)
        TextView zanNum;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
